package com.zhenwei.zscm.controller;

import com.zhenwei.zscm.common.annotations.Insert;
import com.zhenwei.zscm.common.annotations.MethodName;
import com.zhenwei.zscm.common.annotations.Update;
import com.zhenwei.zscm.common.annotations.Update2;
import com.zhenwei.zscm.common.base.RestResult;
import com.zhenwei.zscm.model.vo.user.QueryUserVO;
import com.zhenwei.zscm.model.vo.user.UserVO;
import com.zhenwei.zscm.service.UserService;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/user")
@AllArgsConstructor
@RestController
@MethodName("用户管理")
public class UserController {
    private UserService userService;

    @GetMapping("/login")
    public RestResult login(@RequestParam String userName,@RequestParam String password){
        return userService.login(userName, password);
    }

    @MethodName("查询用户列表")
    @PostMapping("/page")
    public RestResult page(@RequestBody QueryUserVO vo){
        return userService.getUserPageList(vo);
    }
    @MethodName("添加用户")
    @PostMapping("/create")
    public RestResult create(@RequestBody  @Validated({Insert.class}) UserVO vo) {
        return userService.createUser(vo);
    }
    @MethodName("修改用户信息")
    @PostMapping("/update")
    public RestResult update(@RequestBody @Validated({Update.class}) UserVO vo) {
        return userService.updateUser(vo);
    }
    @MethodName("修改用户密码")
    @PostMapping("/passwd/update")
    public RestResult updatePwd(@RequestBody @Validated({Update2.class}) UserVO vo ) {
        return userService.updateUserPwd(vo);
    }
    @MethodName("删除用户")
    @GetMapping("/delete")
    public RestResult delete(@RequestParam @NotEmpty(message = "用户ID不能为空") String userId) {
        return userService.delete(userId);
    }

    @MethodName("获取用户详情")
    @GetMapping("/detail")
    public  RestResult detail(@RequestParam @NotEmpty(message = "用户ID不能为空") String userId) {
        return userService.detail(userId);
    }
}
